{% extends "automan/template.html" %}
{% load staticfiles %}
{% block title %}发布单列表{% endblock %}

{% block ext-css %}
<link rel="stylesheet" href="{% static 'lib/font-awesome-4.7.0/css/font-awesome.min.css' %}"/>
{% endblock %}

{% block content %}
<div>
    <span class="l">
        <a class="btn btn-primary radius" href="{% url 'deploy:create' %}">新建发布单></a>
    </span>
    <span class="select-box inline r">
        {% include "automan/filter.html" %}
        <button type="submit" class="btn btn-success filter_btn" >过滤</button>
        {% include "automan/search.html" %}
    </span>
</div><br/><br/>

<table class="table table-border table-bordered table-bg">
    <thead>
        <th>发布单名称</th>
        <th>所属APP</th>
        <th>Git Branch</th>
        <th>增量/全量</th>
        <th>部署类型</th>
        <th>操作</th>
        <th>用户</th>
        <th>更新时间</th>
    </thead>
    <tbody>
        {% for item in object_list %}
        <tr class="text-l">
            <td>
                <span data-toggle="tooltip" data-placement="bottom" title="{{ item.description }}">
                    <a href="{% url 'deploy:detail' pk=item.id %}">{{ item.name }}</a>
                </span>
            </td>
            <td>{{ item.app_name }}</td>
            <td>{{ item.branch_build }}</td>
            <td>
                {% ifequal item.is_inc_tot 'TOT' %}
                <span class="label label-secondary radius">全量</span>
                {% endifequal %}
                {% ifequal item.is_inc_tot 'INC' %}
                <span class="label label-secondary radius">增量</span>
                {% endifequal %}
            </td>
            <td>
                {% ifequal item.deploy_type 'deployall' %}
                    <span class="label label-primary radius">程序及配置</span>
                {% endifequal %}
                {% ifequal item.deploy_type 'deploypkg' %}
                    <span class="label label-primary radius">程序</span>
                {% endifequal %}
                {% ifequal item.deploy_type 'deploycfg' %}
                    <span class="label label-secondary radius">配置</span>
                {% endifequal %}
            </td>
            <td>
                {% ifequal item.deploy_status.name 'CREATE' %}
                    <button class="btn btn-primary-outline radius buildBtn" app_name="{{ item.app_name }}" deploy_version="{{ item.name }}" jenkins_job="{{ item.app_name.jenkins_job }}">编译</button>
                {% endifequal %}
                {% ifequal item.deploy_status.name 'BUILD' %}
                    <button class="btn btn-primary-outline radius checkBtn" app_name="{{ item.app_name }}" deploy_version="{{ item.name }}">检测</button>
                {% endifequal %}
            </td>
            <td>{{ item.create_user }}</td>
            <td>{{ item.change_date }}</td>
        </tr>
        {% endfor %}
    </tbody>
</table>
<br/>
{#分页    #}
{% include "automan/paginate.html" %}
{% endblock %}

{% block modal %}
{#模态对话框，单独置于页面主体之外，避免被模态对话框被页面遮挡    #}
<div id="modal-demo" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content radius">
            <div class="modal-header">
                <h3 class="modal-title">构建程序发布包</h3>
                <a class="close" data-dismiss="modal" aria-hidden="true" href="javascript:void();" onclick="modal_close()">×</a>
            </div>
            <div class="modal-body">
                <p>
                    APP名称：<span id="modal_app_name"></span><br/>
                    发布单：<span id="modal_deploy_version" class="label label-primary radius"></span><br/>
                    Jenkins Job：<span id="modal_jenkins_job"></span><br/>
                    Jenkins Url：<span id="modal_jenkins_url"></span><br/><br/>
                    <button class="btn btn-danger btn_gen_pkg">开始构建</button>
                    <span id="build_progress"></span>
                </p>
            </div>
            <div class="modal-footer">
                <button class="btn" data-dismiss="modal" aria-hidden="true" onclick="modal_close()">关闭</button>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block script %}
<script>
$(".search_btn").click(function () {
    var search_pk = $("input[name='search_pk']").val() || "demo";
    if (search_pk == "demo") {
        $("body").Huimodalalert({content: "<span class='c-error'>请输入关键字再进行搜索!", speed: 3000});
        return false;
    }
    search_pk = search_pk.replace(/(^\s*)|(\s*$)/g, "");
    var url = "{% url 'deploy:list' %}?search_pk=" + search_pk;
    console.log(url);
    location.href = url;
});
$(".filter_btn").click(function () {
    var filter_app_name = $("select[name='app_name']").val();
    console.log(filter_app_name);
    if (filter_app_name.length == 0) {
        $("body").Huimodalalert({content: "<span class='c-error'>请选择组件再过滤！</span>", speed: 3000});
        return false;
    } else {
        var url = "{% url 'deploy:list' %}?app_name=" + filter_app_name;
    }
    console.log(url);
    location.href = url;
});
{% include "deploy/build.js" %}
</script>
{% endblock %}